<form action="" method="post">
Share your travel experience: <br>
<textarea rows="5" cols="50" name='text'></textarea>
<input type="submit" name='share' />
</form>
<a href="<?php echo My_URL::app_url('welcome');?>">home</a><br>
Name of Place: <?php echo $page_name;?>
<?php
function comp_comment($cm1, $cm2) {
	if($cm1['pid'] > $cm2['pid']) return 1;
	else if($cm1['pid'] < $cm2['pid']) return -1;
	else if($cm1['tid'] > $cm2['tid']) return 1;
	else if($cm1['tid'] < $cm2['tid']) return -1;
	else if($cm1['time'] < $cm2['time']) return -1;
	else if($cm1['time'] > $cm2['time']) return 1;
	else if($cm1['type'] > $cm2['type']) return 1;
	else if($cm1['type'] < $cm2['type']) return -1;
	else return 0;
}
$comments_temp = array();
foreach($comments as $k=>$comment) {
	$comments_temp[$k] = $comment;
}
$comments = $comments_temp;
usort($comments, "comp_comment");
$threadid = -1;
	$last_pid = -1;
foreach($comments as $comment) {
	if($comment['type'] == Model_UserComments::TYPE_MAINPOST) {
		if($threadid != -1) {
?>
<div id='<?php echo $threadid;?>'></div>
<form class='comment_form'>
<input type='hidden' name='pid' value='<?php echo $last_pid;?>' />
<input type='hidden' name='threadid' value='<?php echo $threadid;?>' />
<textarea rows="2" cols="50" name='comment'></textarea>
<input type="submit" name='post_it' />
</form>
	<?php
			echo "</div>";
		}
		echo "<div class='mainpost'><b>".$comment['uname']."</b>: ".$comment['comment'];
	}
	else echo "<div class='commentpost'><b>".$comment['uname']."</b>: ".$comment['comment']."</div>";
	$threadid = $comment['tid'];
	$last_pid = $comment['pid'];
}
if($threadid != -1) {?>
<div id='<?php echo $threadid;?>'></div>
<form class='comment_form'>
<input type='hidden' name='pid' value='<?php echo $last_pid;?>' />
<input type='hidden' name='threadid' value='<?php echo $threadid;?>' />
<textarea rows="2" cols="50" name='comment'></textarea>
<input type="submit" name='post_it' />
</form>
<?php echo "</div>";}?>